package org.jeecg.modules.pur.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.pur.entity.PurSupplierPool;
import org.jeecg.modules.pur.service.IPurSupplierPoolService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

 /**
 * @Description: 外围采购供应商库
 * @Author: jeecg-boot
 * @Date:   2022-11-14
 * @Version: V1.0
 */
@Api(tags="外围采购供应商库")
@RestController
@RequestMapping("/pur/purSupplierPool")
@Slf4j
public class PurSupplierPoolController extends JeecgController<PurSupplierPool, IPurSupplierPoolService> {
	@Autowired
	private IPurSupplierPoolService purSupplierPoolService;

	/**
	 * 分页列表查询
	 *
	 * @param purSupplierPool
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@AutoLog(value = "外围采购供应商库-分页列表查询")
	@ApiOperation(value="外围采购供应商库-分页列表查询", notes="外围采购供应商库-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList(PurSupplierPool purSupplierPool,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<PurSupplierPool> queryWrapper = QueryGenerator.initQueryWrapper(purSupplierPool, req.getParameterMap());
		Page<PurSupplierPool> page = new Page<PurSupplierPool>(pageNo, pageSize);
		IPage<PurSupplierPool> pageList = purSupplierPoolService.page(page, queryWrapper);
		return Result.OK(pageList);
	}

	/**
	 *   添加
	 *
	 * @param purSupplierPool
	 * @return
	 */
	@AutoLog(value = "外围采购供应商库-添加")
	@ApiOperation(value="外围采购供应商库-添加", notes="外围采购供应商库-添加")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody PurSupplierPool purSupplierPool) {
		purSupplierPoolService.save(purSupplierPool);
		return Result.OK("添加成功！");
	}

	/**
	 *  编辑
	 *
	 * @param purSupplierPool
	 * @return
	 */
	@AutoLog(value = "外围采购供应商库-编辑")
	@ApiOperation(value="外围采购供应商库-编辑", notes="外围采购供应商库-编辑")
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody PurSupplierPool purSupplierPool) {
		purSupplierPoolService.updateById(purSupplierPool);
		return Result.OK("编辑成功!");
	}

	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "外围采购供应商库-通过id删除")
	@ApiOperation(value="外围采购供应商库-通过id删除", notes="外围采购供应商库-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		purSupplierPoolService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "外围采购供应商库-批量删除")
	@ApiOperation(value="外围采购供应商库-批量删除", notes="外围采购供应商库-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.purSupplierPoolService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "外围采购供应商库-通过id查询")
	@ApiOperation(value="外围采购供应商库-通过id查询", notes="外围采购供应商库-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		PurSupplierPool purSupplierPool = purSupplierPoolService.getById(id);
		if(purSupplierPool==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(purSupplierPool);
	}

	 /**
	  * 查询所有黑名单的供应商
	  *
	  * @return List<PurSupplierPool>
	  */
	 @AutoLog(value = "外围采购供应商库-查询所有黑名单")
	 @ApiOperation(value="外围采购供应商库-查询所有黑名单", notes="外围采购供应商库-查询所有黑名单")
	 @GetMapping(value = "/queryAllBlacklist")
	 public Result<?> queryAllBlacklist() {
		 List<PurSupplierPool> purSupplierPool = purSupplierPoolService.selectAllBlacklist();
		 if(purSupplierPool == null) {
			 return Result.error("未找到对应数据");
		 }
		 return Result.OK(purSupplierPool);
	 }


	 /**
	  * 查询所有外委供应商
	  *
	  * @return List<PurSupplierPool>
	  */
	 @AutoLog(value = "外围采购供应商库-查询所有外委供应商")
	 @ApiOperation(value="外围采购供应商库-查询所有外委供应商", notes="外围采购供应商库-查询所有外委供应商")
	 @GetMapping(value = "/queryAllSubContractor")
	 public Result<?> queryAllSubContractor() {
		 List<PurSupplierPool> purSupplierPool = purSupplierPoolService.selectAllSubContractor();
		 if(purSupplierPool == null) {
			 return Result.error("未找到对应数据");
		 }
		 return Result.OK(purSupplierPool);
	 }

	 /**
	  * 查询所有采购供应商
	  *
	  * @return List<PurSupplierPool>
	  */
	 @AutoLog(value = "外围采购供应商库-查询采购供应商")
	 @ApiOperation(value="外围采购供应商库-查询采购供应商", notes="外围采购供应商库-查询采购供应商")
	 @GetMapping(value = "/queryAllProcurement")
	 public Result<?> queryAllProcurement() {
		 List<PurSupplierPool> purSupplierPool = purSupplierPoolService.selectAllProcurement();
		 if(purSupplierPool == null) {
			 return Result.error("未找到对应数据");
		 }
		 return Result.OK(purSupplierPool);
	 }

    /**
    * 导出excel
    *
    * @param request
    * @param purSupplierPool
    */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, PurSupplierPool purSupplierPool) {
        return super.exportXls(request, purSupplierPool, PurSupplierPool.class, "外围采购供应商库");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, PurSupplierPool.class);
    }

}
